<?php
	class Page extends _obhandler{

		var $title = '';
		var $meta = array();
		
		var $links = array();
		var $css = '';
		
		var $bd = '';
			
		function add_css($href){
			$this->links[] = array('stylesheet', 'text/css', $href);
		}
		
		function insert_link($rel, $type, $href){
			$this->links[] = array($rel, $type, $href);
		}
		
		function cssln($str){
			$this->css .= "$str\n";
		}
		
		function ln($str){
			$this->bd .= "$str\n";
		}
		
		function obln($str){
			$this->ob .= "$str\n";
		}
			
		function flush(){
			$this->build();
			parent::flush();	
		}
		
		function build(){
			$this->open_head();
			$this->write_js();
			$this->write_links();
			$this->write_css();
			$this->close_head();
			$this->write_body();
			$this->close_html();
		}
	
		function open_head(){
			$this->obln('<?xml version="1.0" encoding="UTF-8"?>');
			foreach($this->links as $link) if($link[0] == 'stylesheet') $this->obln('<?xml-stylesheet type="text/css" href="'.$link[2].'"?>');
			$this->obln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"');
			$this->obln("\t".'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
			$this->obln('<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">');
			$this->obln('<head>');
			$this->obln("<title>".$this->title."</title>");
			foreach($this->headers as $k=>$v) $this->obln("<meta http-equiv=\"$k\" content=\"$v\" />");
			foreach($this->meta as $k=>$v) $this->obln("<meta name=\"$k\" content=\"$v\" />");	
		}
		
		function write_js(){
			if($this->jst) $this->obln($this->jst->write_string());
		}
		
		function write_links(){
			foreach($this->links as $link) $this->obln('<link rel="'.$link[0].'" type="'.$link[1].'" href="'.$link[2].'" />');	
		}
		
		function write_css(){
			if(!$this->css) return;
			$this->obln('<style type="text/css">');
			$this->obln($this->css);
			$this->obln('</style>');
		}

		function close_head(){
			$this->obln("</head>\n<body>");
		}
		
		function write_body(){
			$this->obln($this->bd);
		}
		
		function close_html(){
			$this->obln('</body>');
			$this->obln('</html>');
		}	
	}

